package com.laivi.basic.module.crawler;

import com.laivi.basic.model.crawler.LinkSet;

/**
 * @author laivi.zhu@gmail.com
 * @date 2014-4-17
 * description:
 */
public class ParserThread implements Runnable {

	private Parsers parser;
	
	private String url;
	
	private String key;
	
	private LinkSet links;
	
	
	public ParserThread(Parsers parser,LinkSet links, String url,String key) {
		this.parser = parser;
		this.links=links;
		this.url = url;
		this.key=key;
	}

	@Override
	public void run() {
		try{
        	if(parser.saveData(key,parser.parser(url))){
        		parser.addParserNum();
        	}
        	if(!links.isVisited(url)){
        		links.addVisitedUrl(url);
        	}
    	}catch(Exception e){
    		e.printStackTrace();
    	}
	}

}
